package com.caimiao.miao.widget;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.caimiao.miao.R;

public class HttpBarDialog {
    private Dialog mDialog;
    private TextView mTvContent;
    private OnCancelListener mOnCancelListener;

    public interface OnCancelListener {
        void onCancelProgress();
    }

    public HttpBarDialog(final Context mContext, OnCancelListener listener) {
        mDialog = new Dialog(mContext, R.style.common_dialog_radius);
        this.mOnCancelListener = listener;
        mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                if (mOnCancelListener != null) mOnCancelListener.onCancelProgress();
            }
        });
        mDialog.setCanceledOnTouchOutside(false);
        View root = LayoutInflater.from(mContext).inflate(R.layout.http_progress_dialog, null);
        mTvContent = root.findViewById(R.id.progress_dialog_tv_msg);
        mDialog.setContentView(root);
    }

    public HttpBarDialog setContent(String msg) {
        mTvContent.setText(msg);
        return this;
    }

    public HttpBarDialog setContent(int msg) {
        mTvContent.setText(msg);
        return this;
    }

    public HttpBarDialog setCancelable(boolean flag) {
        mDialog.setCancelable(flag);
        return this;
    }

    public void show() {
        mDialog.show();
    }

    public void dismiss() {
        mDialog.dismiss();
    }

    public boolean isShowing() {
        return mDialog.isShowing();
    }
}
